﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;
using CsharpTrainer.Domain.Concurrency.Progress;
using System.Threading;

namespace SharpTrainer.Concurrency
{
    class ProgressTest : ITestCase
    {
        public void Run()
        {
            Console.Clear();
            
            var tcs = new CancellationTokenSource();
            CancellationToken ct = tcs.Token;
            IImport import = new PdfImport();

            Task importTask = import.ImportFilesAsync(@"E:\MyBook\RecentRead\GameProgramming", ct, new Progress<ImportProgress>(ProgressHelper.DisplayProgress));

            while (!importTask.IsCompleted)
            {
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Q)
                {
                    tcs.Cancel();
                }
                Thread.Sleep(250);
            }

            Console.WriteLine(importTask.Status);
        }
    }
}
